package ttOrder.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ttOrder.dao.inter.UserMapper;
import ttOrder.model.po.DinnerTable;
import ttOrder.model.po.User;
import ttOrder.model.vo.UserVO;



@Service
@Transactional
public class UserServiceImpl extends abstractService<User>{

	@Autowired
	private UserMapper userMapper;
	
	/* operate with vo class */
	
	public UserVO getByKey(UserVO keyvo) {
		UserVO vo = new UserVO();
		if (keyvo != null) {
			User key = new User();
			BeanUtils.copyProperties(keyvo, key);
			User po = new User();
			po = userMapper.selectByPrimaryKey(key);
			BeanUtils.copyProperties(po, vo);
		}
		return vo;
	}
	
	/* operate with po class */

	@Override
	public List<User> getAll() {
		return userMapper.selectAll();
	}
	
	public List<UserVO> getAllVO() {
		List<UserVO> volist = new ArrayList<UserVO>();
		List<User> polist = userMapper.selectAll();
		if (polist.size() > 0) {
			UserVO vo = null;
			for (User po : polist) {
				vo = new UserVO();
				BeanUtils.copyProperties(po, vo);
				volist.add(vo);
			}
		}
		return volist;
	}
	
	@Override
	public List<User> getByEntity(User record) {
		return userMapper.select(record);
	}

	@Override
	public User getByKey(User key) {
		return userMapper.selectByPrimaryKey(key);
	}

	@Override
	public int insert(User record) {
		return userMapper.insert(record);
	}

	@Override
	public int update(User record) {
		return userMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int deleteByKey(User key) {
		return userMapper.deleteByPrimaryKey(key);
	}

	@Override
	public int deleteByEntity(User record) {
		return userMapper.delete(record);
	}

	@Override
	public int getCount(User record) {
		return userMapper.selectCount(record);
	}

	public int updateUserLoginFailCount(User result) {
		return userMapper.updateByPrimaryKeySelective(result);
		
	}

	public int updateUserLastLockTime(User result) {
		return userMapper.updateByPrimaryKeySelective(result);
		
	}
	
	
	

}
